${module.copyRight!}
package ${module.packageName}.web.admin;



import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import klg.common.model.EasyUIPage;
import klg.common.model.JsonData;
import klg.query.jpa.expr.AExpr;
import klg.query.jpa.expr.AttrExpression;
import klg.query.jpa.expr.AttrSimpleExpression;

import ${module.packageName}.entity.${tablemeta.entityName};
import ${module.packageName}.entity.${tablemeta.entityName}_;
import ${module.packageName}.service.${tablemeta.entityName}Service;



/**
 *
 * 
 * Generated by fieldmeta.com at ${nowTime}
 *
 */

@Controller("admin${tablemeta.entityName}Controller")
@RequestMapping("/admin/action/${entityNameOfAllLowcase}")
public class ${tablemeta.entityName}Controller {
	@Autowired
	${tablemeta.entityName}Service ${entityNameOfFirstLowcase}Service;
	
	@ResponseBody
	@RequestMapping("/add")
	public JsonData add(
			@ModelAttribute ${tablemeta.entityName} ${entityNameOfFirstLowcase}){
		
		${entityNameOfFirstLowcase}Service.save(${entityNameOfFirstLowcase});
		return JsonData.success();
	}
	
	
	@ResponseBody
	@RequestMapping("/edit")
	public JsonData edit(
			@ModelAttribute ${tablemeta.entityName} ${entityNameOfFirstLowcase}){
		
		${entityNameOfFirstLowcase}Service.update(${entityNameOfFirstLowcase});
		return JsonData.success();
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public JsonData delete(
			@RequestParam Long id){
		
		${entityNameOfFirstLowcase}Service.delete(id);
		return JsonData.success();
	}
	
	@ResponseBody
	@RequestMapping("/findpage")
	public EasyUIPage findpage(
			@ModelAttribute ${tablemeta.entityName} ${entityNameOfFirstLowcase},
			@RequestParam int page,
			@RequestParam int rows){
		Pageable pageable=new PageRequest(page<1?0:page-1, rows, new Sort(Direction.DESC,"id"));
		List<AttrExpression> aes = new ArrayList<>();
<#list allPageFields as pageField>
	<#if (pageField.canQuery == "yes") && (pageField.queryType != "between")>
		aes.add(AExpr.${pageField.queryType}(${tablemeta.entityName}_.${pageField.entityField.attrName}, ${entityNameOfFirstLowcase}.get${pageField.entityField.attrName?cap_first}()).igEmpty());
	</#if>
</#list>
		Page<${tablemeta.entityName}> pageData=${entityNameOfFirstLowcase}Service.findPage(pageable, aes.toArray(new AttrSimpleExpression[aes.size()]));
		return new EasyUIPage(pageData);
	}
	
	@ResponseBody
	@RequestMapping("/findlist")
	public JsonData findlist(
			@ModelAttribute ${tablemeta.entityName} ${entityNameOfFirstLowcase}){
		
		List<${tablemeta.entityName}> listData=${entityNameOfFirstLowcase}Service.findList(${entityNameOfFirstLowcase}, new Sort(Direction.DESC,"id"));
		return JsonData.success(listData);
	}	
}
